Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit.form() + queryString-values 1

Status
Not open for further replies.

BennySHS

Programmer
Mar 15, 2005
32
DE
hi there,

i want to submit a form via form.submit, and I want to know if there is a way to give the form.submit() a queryString values with it.

I want to do this because there are several links on my page which can submit the form and I need to know which link was clicked.

Thanks a lot,
greets,
ben
 
Why not use buttons instead of links? That way, you can simply detect the presence of a specific button name. The buttons can easily be styled to look like links... and better still, people without JS can use it.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I would suggest you add a hidden field to your form. By default this is empty. If you click a URL then set the value of the hidden field to reflect the URL that was clicked. You can then do a server-side test to see if the value was empty (the user just submitted the form normally or has javascript off) or if the value is not empty... then it contains data specific to the URL that was clicked to submit the form.

That's how I would do it (based on what you have told us).

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Hi there,

thaks a lot for your answers.

@BillyRayPreachersSon:

How would you do this ? i want five buttons which have all the same name butt different valuse. But unfortunately the value-attribut appears as label for the button - and so its not possible to do so. Or i'm wrong ?

greets,
ben
 
hey dan,

yes the buttons need the same name, because it looks very ugly to the user if the label of the button is the ID of a customer instead of "delete" or so...

the thing is I got a list with people-accounts and I need a button for each to delete them.
Its not the first time I have problems to solve this, at least if I want to do it completely serverside.

Perhaps there's a way to give a background-pic on the button and set fontcolor and background-color of the buttons to the same to "overwrite" the value ?? i'll try that later...

greetings,
ben
 
it looks very ugly to the user if the label of the button is the ID of a customer instead of "delete" or so...

What? Are you confusing the NAME with the VALUE of the button? Who cares what the back-end code NAME is. No user I know of (who isn't a web developer) ever looks at the source of a page .

You code yor pages to make it easy for you. Call your button names "fred", "wilma", and "betty" if you want, as long as the values reflect what the button does.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
of course the user dont care about the name-attribut of my buttons, but my script does.


with the NAME-attribut i can get the VALUES of an element.

<input type="submit" name="delete" value="34">

if (true == isset($_POST['delete']))
{
echo $_POST['delete'] // output: 34
}

Plesase explain me how to make submit-buttons with different VALUES but the same NAME and the same text on it for the users.


Perhaps I'm totally wrong, but I guess there's no solutions but javascript for that.

greets,
ben
 
Make a hidden form field. Set an onclick on all your buttons to put the appropriate data into the hidden field (via a function). This hidden field will be submitted regardless of the button you clicked when the form is submitted (which you can do using javascript as I have). You can then access this value server-side.

Code:
<html><head><title>Test</title>
<script type="text/javascript">
function setData(_data) {
	document.forms['myForm'].elements['hdn_data'].value = _data;
	document.forms['myForm'].submit();
}
</script>
</head>
<body>
<form name="myForm" method="post" action="">
	<input type="text" name="hdn_data" value="">
	<input type="button" value="Submit Button 1" onclick="setData('Button 1');">
	<input type="button" value="Submit Button 2" onclick="setData('Button 2');">
	<input type="button" value="Submit Button 3" onclick="setData('Button 3');">
</form>
</body></html>

Note that I am using <input type="button"...> not type="submit" in this instance.

Hopefully this will give you some ideas!

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Ben,

I think our wires got crossed at some point. You said:

i want five buttons which have all the same name butt different valuse. But unfortunately the value-attribut appears as label for the button

I am suggesting have 5 different buttons with 5 different names, and 5 different values. Then your server-side code simply detects which of the 5 buttons were pressed by seeing which 4 are absent.

Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
hey all again!

@BabyJeffy: thx for this solution, I've made it this way and its ok so ;)

@BillyRayPreachersSon
sorry for the confusion, I have some problems to write a "clear" english...Sometimes its hard for me to exactly say what I mean...I'm still learning ;)


thx again, and I'm very happy 'bout this forum,
greetings,
ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top