LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2010, 09:04 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
passing values through pages


I have the following snippet HTML code:
Quote:
<table id="profile">

<tr>...............</tr>

<tr>
<td width="40%">
.................
</td>
<td>
<input id="wue" type="hidden" name="params" value="[% user %] [% email %]" />
<input type="button" value="Add/Change" onclick="return del()" />
</td>
<td>
........
</td>
</tr>
and the following javascript code:
Quote:
function del() {

if (document.getElementById) {
var hiddens = document.getElementById("wue").value;
var args = hiddens.split(" ");

var tabella = document.getElementById("profile");
tabella.deleteRow(1);
x = tabella.insertRow(1);
x.innerHTML = "<td colspan='3'> \
<form action='/cgi-bin/save.cgi' method='POST'> \
<input type='text' name='name' size='30' /> \
<input type='hidden' name='params' value='args[0] args[1]" /> \
<input type='submit' value='Save' /> \
</form> \
</td>";


}

}
The code almost works... The problem is that args[0] and args[1] are parameters JavaScript and I pass javascript code to Perl/CGI code. My program don't interpolate javascript variables.

save.cgi begin with:
Quote:
my $cgi = CGI->new();
print $cgi->header('text/html');

my @params = split(' ',$cgi->param('params'));
How can pass values in args[0] and args[1] to Perl/CGI script?

Thank you in advance to answers,
savio

Last edited by shifter; 05-23-2010 at 09:06 AM.
 
Old 05-23-2010, 10:25 AM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
The problem here is that, unlike Perl and PHP, JavaScript does not use a special character to indicate a variable name, meaning that you can't just thrown one into the middle of a string and expect it to be substituted.

In the following line, JavaScript sees the variable names as just normal text:

Quote:
Originally Posted by shifter View Post
Code:
<input type='hidden' name='params' value='args[0] args[1]" />
Instead, you have to concatenate the variables onto (or into) the string:

Code:
<input type='hidden' name='params' value='" + args[0] + " " + args[1] + "' />\

Last edited by Robhogg; 05-23-2010 at 11:13 AM.
 
Old 05-23-2010, 02:13 PM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Ok, thank you, it works!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
array - passing values to sed command casperdaghost Linux - Newbie 3 08-21-2009 05:43 AM
Passing float values in FIFO navderm Programming 3 01-04-2009 03:00 PM
perl - passing values to subroutines sporty Programming 7 08-08-2006 09:13 AM
Passing form values between multiple forms!! AskMe Programming 5 09-07-2005 07:44 PM
passing values in shell pantera Programming 1 05-20-2004 09:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration