...

View Full Version : Pass a variable with html or javascript



sher_amf
08-29-2010, 03:53 PM
what i want is that i could send the value that is stored in the array

For example i have array of
result[0] = 1
can i put in my form

<form action="2.html?right=result[0]&wrong=0" method="post">

instead of 1?


<form action="2.html?right=1&wrong=0" method="post">

html 1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
var result=new Array(); // regular array (add an optional integer
result[0]=2; // argument to control array's size)
var a = parseInt(result[0]);
result[1]="0";

document.write(result[0]);
document.write(a);


</script>
<table width="315" border="1">
<tr>
<td width="107"> -13-6=-23 </td>
<td width="76"><form action="2.html?right=a&wrong=0" method="post"><INPUT TYPE="submit" VALUE="RIGHT"><input type="hidden" name="result[0]"/></form></td>
<td width="110"><form action="2.html?right=0&wrong=1" method="post"><INPUT TYPE="submit" VALUE="WRONG"></form></td>
</tr>
</table>


</body>
</html>



html 2

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
// End -->
</script>
</head>

<body>
<table width="315" border="1">
<tr>
<td width="107"> -13-8=-21 </td>
<td width="76">&nbsp;</td>
<td width="110">&nbsp;</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
var result=new Array();
<!-- Begin
result[0] = 1;

//result[0] = result[0] + parseInt(unescape(params["right"]));
result[0] = unescape(params["right"]);
result[1] = unescape(params["wrong"]);
var name = unescape(params["name"]);

// regular array (add an optional integer
document.write(result[0] + result[1]);
document.write(name);
// End -->
</script>
</body>
</html>

PradeepKr
08-30-2010, 06:06 AM
You want to do it in client side script only?
WHy not use server side script to handle requests?

teedoff
08-30-2010, 03:00 PM
www.w3schools.com/php/default.asp

PHP can handle this rather simply. Look over the tutorials in the link I gave.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum