?
Solved

Add apostrophe to hidden form field

Posted on 2003-11-19
10
Medium Priority
?
336 Views
Last Modified: 2012-08-14
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.value = document.listform.sBus.value + "'" + busObj.value + "',";
          }
     if (indObj == true) {
       document.listform.sInd.value = document.listform.sInd.value + "'" + indObj.value + "',";
          }
    }
}
0
Comment
Question by:whargra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9781071
function AddIt()
{
   var busObj;
   var indObj;
   //Get value
      busObj = <% Response.Write Request.Form("sBus")%>;
    indObj = <% Response.Write Request.Form("sInd")%>;   {
     if (busObj) {
       document.listform.sBus.value = document.listform.sBus.value + "'" + busObj + "',";
         }
     if (indObj) {
       document.listform.sInd.value = document.listform.sInd.value + "'" + indObj + "',";
         }
    }
}
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9781074
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.value = document.listform.sBus.value + "'" + busObj + "',";
         }
     if (indObj) {
       document.listform.sInd.value = document.listform.sInd.value + "'" + 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>


0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9781434
This surely

<input type="hidden" name="sBus" value="'<% Response.Write Request.Form("sBus")%>'">
<input type="hidden" name="sInd" value="'<% Response.Write Request.Form("sInd")%>'">
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:whargra
ID: 9781624
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'
0
 
LVL 25

Expert Comment

by:devic
ID: 9783182
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")%>"><br>
<input style=width:100% type="text" name="sInd" value="<%= Request.Form("sInd")%>"><br>
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 1000 total points
ID: 9783216
Check this:

<form name="listform">
<input type="text" name="sBus" value="'a, b, c, d'">
<input type="text" name="sInd" value="i, j, k, l">
</form>

<script>
function AddIt()
{
   var busObj;
   var indObj;
   //Get objects:
   busObj = document.listform.sBus;
   indObj = document.listform.sInd;
   busObj.value = busObj.value.replace(/\'?(\w+)\'?/g,"'$1'");
   indObj.value = indObj.value.replace(/\'?(\w+)\'?/g,"'$1'");
}
AddIt()
</script>


0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9783254
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>



0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9783698
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").replace( /(\w+)/g ,"'$1'")%>">

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9785105
LOL :-)
0
 
LVL 3

Expert Comment

by:xiong8086
ID: 9785561
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(39) %>>
<input type="hidden" name="sInd" value=<%= chr(39)&Request.Form("sInd")&chr(39)%>>
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question