JS replacement string Replace function using

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title>Untitled</title>
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/>

<script type= "Text/javascript" language= "JavaScript" >

function GetValue (id,alts)
{
var strb =alts; Answer
var stra =id; Problem ID (must be passed in as a string)
var Stringobj=document.getelementbyid ("Hidden1"). Value; Question Answer Collection
var s = stringobj.indexof (stra); Get the index of the problem

if (S >=0)
{
Modify
var ss=s+ (stra.length); Get the length of the question answer
Alert (ss);
alert (stringobj);
var SSD = stringobj.substr (ss,stringobj.length);
Alert (SSD);
var ssf =ssd.indexof (";");
alert (SSF);
var sss=stringobj.substr (ss,ssf+1); Get answers
Alert (SSS);
var strc=stra+ "," +strb+ ";"; The new answer
var newstr=stringobj.replace (STRA+SSS,STRC); The data after the replacement
}

Else
{
New
var strc=stra+ "," +strb+ ";";
STRINGOBJ=STRINGOBJ+STRC;
Newstr=stringobj;
}
alert (NEWSTR);
document.getElementById ("Hidden1"). Value=newstr;
}
</script>

<body>
<form id= "Form1" runat= "Server" >
<table>
<tr>
<td> <input id= "id1" type= "text" value= "You know what? "/> </td>
<td> <input id= "ID2" type= "Radio" name= "Radio1" value= "Know" onclick= "GetValue (' 1 ', ' Know ')" > Know </td>
<td> <input id= "ID3" type= "Radio" name= "Radio1" value= "Don't Know" onclick= "GetValue (' 1 ', ' Don't Know ')"/> Don't know </td >
</tr>

<tr>
<td> <input id= "Id4" type= "text" value= "You know what? "/> </td>
<td> <input id= "ID5" type= "Radio" name= "Radio2" value= "Know" onclick= "GetValue (' 2 ', ' Know ')"/> Know </td>
<td> <input id= "ID6" type= "Radio" name= "Radio2" value= "Don't Know" onclick= "GetValue (' 2 ', ' Don't Know ')"/> Don't know </td >
</tr>

<tr>
<td> <input id= "Id7" type= "text" value= "You know what? "/> </td>
<td> <input id= "ID8" type= "Radio" name= "Radio3" value= "Know" onclick= "GetValue (' 3 ', ' Know ')"/> Know </td>
<td> <input id= "ID9" type= "Radio" name= "Radio3" value= "Don't Know" onclick= "GetValue (' 3 ', ' Don't Know ')"/> Don't know </td >
</tr>

<input type= "text" id= "Hidden1" >
</table>


</form>
</body>


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.