Modify my script --- pass parameters....

r_kar
r_kar used Ask the Experts™
on
Hi all,

Please cut the code and provide a solution.

Code:--

<html><head>
<script language ="javascript">
<!--
function setDraft()
{
var s1,s2,s3
 s1 = document.test.one.value;
 s2 = document.test.two.value;
 s3 = document.test.three.value;
<-- Here i need a code -->

}
-->
</script>
</head>
<body><form name="test" method ="post">
<input type="hidden" name="one" value="first">
<input type="hidden" name="two" value="Second">
<input type="hidden" name="three" value="third">
<input type="button" name="submit" value="Draft" onClick="setDraft()">
<form>
</body>
</html>

I had a doubt to pass parameter while submitting this form. I have to pass s1,s2,s3 to start.php
i tried to give these values in setDraft() as
location.href = /root/start.php?val=s1&val2=s2&val3=s3

In start.php i need to catch these values.
Page should load in the same window (that's why i gave as location.href)

How can i write that... Please provide an answer

 Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I'm not sure that I've understand you correctly but if I do than heeeeree goooooooooes solution ;)

1)( hardest )
<html><head>
<script language ="javascript">
<!--
function setDraft(obj)
{
var s1,s2,s3
s1 = document.test.one.value;
s2 = document.test.two.value;
s3 = document.test.three.value;
obj.form.submit();
}
-->
</script>
</head>
<body><form name="test" method ="post">
<input type="hidden" name="one" value="first">
<input type="hidden" name="two" value="Second">
<input type="hidden" name="three" value="third">
<input type="button" name="submit" value="Draft" onClick="setDraft(this)">
<form>
</body>
</html>

2) (easiest)

<html><head>
</head>
<body>
<form action="/root/start.php" method ="post">
<input type="hidden" name="one" value="first">
<input type="hidden" name="two" value="Second">
<input type="hidden" name="three" value="third">
<input type="submit" value="Draft">
<form>
</body>
</html>
<html><head>
<script language ="javascript">
<!--
function setDraft()
{
var s1,s2,s3
s1 = document.test.one.value;
s2 = document.test.two.value;
s3 = document.test.three.value;
window.location.replace('start.php?s1='+s1+'&s2='+s2+'&s3='+s3);
}
-->
</script>
</head>
<body><form name="test" method ="post">
<input type="hidden" name="one" value="first">
<input type="hidden" name="two" value="Second">
<input type="hidden" name="three" value="third">
<input type="button" name="button" value="Draft" onClick="setDraft()">
<form>
</body>
</html>
------
But why in this manner?

I am really not clear what you want to achieve here.
But you can just do this with HTML page.

<html><head>
</head>
<body><form name="test" method ="GET" action="/root/start.php">
<input type="hidden" name="val" value="first">
<input type="hidden" name="val2" value="Second">
<input type="hidden" name="val3" value="third">
<input type="button" name="submit" value="Draft">
<form>
</body>
</html>

This will submit form using GET method which will look something like
/root/start.php?val=s1&val2=s2&val3=s3

Regards,
JD
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Author

Commented:
Hi all,
Thanks for all comments.
I will go through it and award the ee points.

I am expecting an answer like what Ray_Adams  wrote.
In my form i have many operation(means more than one function) in that i have to call different php's and input will be different for each php.
What i had given is a sample code.

Thanks
r_kar

Commented:
Strange question. what for ?
Why don't you simply name your  fields s1,s2... and post the form normally?

<html><head>
<script language ="javascript">
<!--
function setDraft()
{
document.test.submit();
}
-->
</script>
</head>
<body><form name="test" method ="post">
<input type="hidden" name="s1" value="first">
<input type="hidden" name="s2" value="Second">
<input type="hidden" name="s3" value="third">
<input type="button" name="submit" value="Draft" onClick="setDraft()">
<form>
</body>
</html>

Author

Commented:
Thanks a lot

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial