whargra
asked on
Add apostrophe to hidden form field
I'm passing values using a hidden field from form page to form page. What I need to do is add apostrophes to the hidden field. I have this working from the select box when the values are added but some IE browsers aren't carrying the values even though they are the same version. So I need to add these on the last form.
Here is the hidden field that is carrying the values and that I want to add the ticks to:
<input type="hidden" name="sBus" value="<% Response.Write Request.Form("sBus")%>">
<input type="hidden" name="sInd" value="<% Response.Write Request.Form("sInd")%>">
Here is the javascript I wrote to add them but doesn't seem quite right:
function AddIt()
{
var busObj;
var indObj;
//Get value
busObj = <% Response.Write Request.Form("sBus")%>;
indObj = <% Response.Write Request.Form("sInd")%>;
{
if (busObj == true) {
document.listform.sBus.val ue = document.listform.sBus.val ue + "'" + busObj.value + "',";
}
if (indObj == true) {
document.listform.sInd.val ue = document.listform.sInd.val ue + "'" + indObj.value + "',";
}
}
}
Here is the hidden field that is carrying the values and that I want to add the ticks to:
<input type="hidden" name="sBus" value="<% Response.Write Request.Form("sBus")%>">
<input type="hidden" name="sInd" value="<% Response.Write Request.Form("sInd")%>">
Here is the javascript I wrote to add them but doesn't seem quite right:
function AddIt()
{
var busObj;
var indObj;
//Get value
busObj = <% Response.Write Request.Form("sBus")%>;
indObj = <% Response.Write Request.Form("sInd")%>;
{
if (busObj == true) {
document.listform.sBus.val
}
if (indObj == true) {
document.listform.sInd.val
}
}
}
here is an example for javascript no server side
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function AddIt()
{
var busObj;
var indObj;
//Get value
busObj = "";
indObj = "john doe";
{
if (busObj) {
document.listform.sBus.val ue = document.listform.sBus.val ue + "'" + busObj + "',";
}
if (indObj) {
document.listform.sInd.val ue = document.listform.sInd.val ue + "'" + indObj + "',";
}
}
} // -->
</script>
</head>
<body>
<form name="listform" method="post" action="">
<input type="text" name="sBus">
<input type="text" name="sInd">
<input type="button" name="btn" value="test" onclick="AddIt();">
</form>
</body>
</html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function AddIt()
{
var busObj;
var indObj;
//Get value
busObj = "";
indObj = "john doe";
{
if (busObj) {
document.listform.sBus.val
}
if (indObj) {
document.listform.sInd.val
}
}
} // -->
</script>
</head>
<body>
<form name="listform" method="post" action="">
<input type="text" name="sBus">
<input type="text" name="sInd">
<input type="button" name="btn" value="test" onclick="AddIt();">
</form>
</body>
</html>
This surely
<input type="hidden" name="sBus" value="'<% Response.Write Request.Form("sBus")%>'">
<input type="hidden" name="sInd" value="'<% Response.Write Request.Form("sInd")%>'">
<input type="hidden" name="sBus" value="'<% Response.Write Request.Form("sBus")%>'">
<input type="hidden" name="sInd" value="'<% Response.Write Request.Form("sInd")%>'">
ASKER
Jay,
With yours I'm getting an Undefined error with the first value result. So I'm going to look at this closer.
Gwyn,
Yours adds the ticks between all the values, not each one. ie, 'a, b, c, d' instead of 'a', 'b', 'c', 'd'
With yours I'm getting an Undefined error with the first value result. So I'm going to look at this closer.
Gwyn,
Yours adds the ticks between all the values, not each one. ie, 'a, b, c, d' instead of 'a', 'b', 'c', 'd'
whargra, i can not get, what are you trying to do.
but anyway, if you work with hidden fields( + with method post :)), then during test change type from HIDDEN to TEXT
to see what are you doing.
<input style=width:100% type="text" name="sBus" value="<%= Request.Form("sBus")%>"><b r>
<input style=width:100% type="text" name="sInd" value="<%= Request.Form("sInd")%>"><b r>
but anyway, if you work with hidden fields( + with method post :)), then during test change type from HIDDEN to TEXT
to see what are you doing.
<input style=width:100% type="text" name="sBus" value="<%= Request.Form("sBus")%>"><b
<input style=width:100% type="text" name="sInd" value="<%= Request.Form("sInd")%>"><b
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or like this:
<html>
<head>
<script>
function AddIt(){
var busObj = document.listform.sBus;
var indObj = document.listform.sInd;
busObj.value = qw(busObj.value);
indObj.value = qw(indObj.value);
}
function qw(wordList){
return wordList.replace(/\'?(\w+) \'?/g,"'$1 '");
}
</script>
</head>
<body onLoad="AddIt()">
<form name="listform">
<input type="text" name="sBus" value="'a, b, c, d'">
<input type="text" name="sInd" value="i, j, k, l">
</form>
</body>
</html>
<html>
<head>
<script>
function AddIt(){
var busObj = document.listform.sBus;
var indObj = document.listform.sInd;
busObj.value = qw(busObj.value);
indObj.value = qw(indObj.value);
}
function qw(wordList){
return wordList.replace(/\'?(\w+)
}
</script>
</head>
<body onLoad="AddIt()">
<form name="listform">
<input type="text" name="sBus" value="'a, b, c, d'">
<input type="text" name="sInd" value="i, j, k, l">
</form>
</body>
</html>
I am not sure exactly what you are trying to do but sever side I believe this is what you want ie a, b, c, d gets changed to 'a', 'b', 'c', 'd'
<%reg= /(\w+)/g
Bus=Request.Form("sBus")
Bus=Bus.replace(reg,"'$1'" )
Ind=Request.Form("sInd")
Ind=Ind.replace(reg,"'$1'" )%>
<input type="hidden" name="sBus" value="<%Response.Write Bus%>">
<input type="hidden" name="sInd" value="<% Response.Write Ind%>">
or more compactly (I think)
<input type="hidden" name="sBus" value=" <%= Request.Form("sBus").repla ce( /(\w+)/g ,"'$1'")%>">
<%reg= /(\w+)/g
Bus=Request.Form("sBus")
Bus=Bus.replace(reg,"'$1'"
Ind=Request.Form("sInd")
Ind=Ind.replace(reg,"'$1'"
<input type="hidden" name="sBus" value="<%Response.Write Bus%>">
<input type="hidden" name="sInd" value="<% Response.Write Ind%>">
or more compactly (I think)
<input type="hidden" name="sBus" value=" <%= Request.Form("sBus").repla
LOL :-)
Can you try this way below? substitute "'" with chr(39) in ASP code, it will work.
<input type="hidden" name="sBus" value=<%= chr(39)& Request.Form("sBus")&chr(3 9) %>>
<input type="hidden" name="sInd" value=<%= chr(39)&Request.Form("sInd ")&chr(39) %>>
<input type="hidden" name="sBus" value=<%= chr(39)& Request.Form("sBus")&chr(3
<input type="hidden" name="sInd" value=<%= chr(39)&Request.Form("sInd
{
var busObj;
var indObj;
//Get value
busObj = <% Response.Write Request.Form("sBus")%>;
indObj = <% Response.Write Request.Form("sInd")%>; {
if (busObj) {
document.listform.sBus.val
}
if (indObj) {
document.listform.sInd.val
}
}
}