Set the default values of select and Radio dynamically

Source: Internet
Author: User

<% @ Page Language = "Java" Import = "Java. util. *, Isa. model. personbean "contenttype =" text/html; charset = gb2312 "pageencoding =" gb2312 "%>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'personmu. jsp 'starting page </title>

<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->

<Script language = JavaScript>

Function check ()
{
VaR id = Document. form1.id. value;
VaR name = Document. form1.name. value;
If (ID = ""){
Alert ("sorry, the member number cannot be blank ");
Return false;
} Else if (name = ""){
Alert ("sorry, name cannot be blank ");
Return false;
}
Else
{
Return true;
}
}
Function initradio (rname, Rvalue ){
VaR robj = Document. getelementsbyname (rname );

For (VAR I = 0; I <robj. length; I ++ ){
If (robj [I]. value = Rvalue ){
Robj [I]. Checked = 'checked ';
}
}
}
</SCRIPT>
</Head>

<Body bgcolor = "# ccffff">
<%
// Prevent unauthorized user logon
String u = (string) Session. getattribute ("ID ");
String L = (string) Session. getattribute ("level ");
If (u = NULL ){
Response. sendredirect ("login. jsp? Err = 1 ");
Return;
}
// Retrieve the information to be displayed from the request
Personbean Pb = (personbean) request. getattribute ("result ");
%>
<Table width = "400" border = "0" align = "center" cellpadding = "0" cellspacing = "0" Height = "250px">
<Tr>
<TD scope = "row" width = "450">
<Form ID = "form1" name = "form1" onsubmit = "Return check ()" method = "Post" Action = "personmuservlet">
<Table width = "400" align = "center">
<Tr>
<TD Height = "30" colspan = "2"> <Div align = "center"> Member & nbsp; & nbsp; Management & nbsp; management </div> </TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> Congo: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "ID" value = "<% = Pb. getpid () %> "readonly =" readonly "maxlength =" 16 "size =" 24 "/>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> last name & nbsp; Name: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "name" value = "<% = Pb. getpname () %>" maxlength = "16" size = "24"/>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> Department & nbsp; door: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "Dept" readonly = "readonly" value = "<% = Pb. getdno () %> "maxlength =" 16 "size =" 24 "/>
</TD>
</Tr>

<Tr>
<TD width = "150" Height = "30" align = "right"> Small & nbsp; group: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "team" readonly = "readonly" value = "<% = Pb. gettno () %> "maxlength =" 16 "size =" 24 "/>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> Position & nbsp; Business: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Select name = "job" size = "1">
<Option value = "ordinary member"> ordinary member </option>
<Option value = "Deputy Leader"> Deputy Leader </option>
<Option value = "Leader"> leader </option>
<Option value = ""> </option>
<Option value = ""> </option>
<Option value = "minister"> Minister </option>
<Option value = "Secretary-General"> Secretary-General </option>
<Option value = "vice president"> Vice President </option>
<Option value = "President"> President </option>
</SELECT>
<! -- Set the default value of select dynamically -->
<Script language = JavaScript>
VaR job = "<% = Pb. getjob () %> ";
Document. getelementsbyname ("job") [0]. value = job;
</SCRIPT>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> professional & nbsp; Industry: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "speciality" value = "<% = Pb. getspeciality () %>" size = "24" maxlength = "24"/>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> sex & nbsp; don't: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input name = "sex" type = "radio" value = "male" Checked = "checked"/> male
<Input type = "radio" name = "sex" value = "female"/> female
<! -- Dynamically set the default value of radio -->
<Script language = JavaScript>
VaR S = "<% = Pb. getsex () %> ";
Initradio ('sex ', S );
</SCRIPT>
</TD>
</Tr>
<Tr>
<TD width = "150" Height = "30" align = "right"> Power & nbsp; Statement: </TD>
& Lt; TD width = "250" align = "Left" & gt;
<Input type = "text" name = "tel" value = "<% = Pb. gettel () %>" maxlength = "15" size = "24"/>
</TD>
</Tr>
<Tr>
<TD colspan = "2" width = "400" Height = "30" align = "center">
<Input type = "Submit" name = "Submit" value = "Submit"/>
</TD>
</Tr>
</Table>
</Form>
</TD>
</Tr>
</Table>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.