|
|
|
|
![]() ![]() |
Feb 19 2008, 07:04 PM
Post
#1
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
I've got two buttons with an onclick event to set the hidden input field to a certain value then continue submitting the form. I have more than one form on display on the page and I don't want to use ids. Is there a way I can reference it from the button/button onclick event?
the forms is laid out like this CODE echo"<form method='post' action='manage.php?manage=news&id={$rs['id']}'>"; echo"<input type='hidden' name='do' value='' />"; echo"<button type='submit' onclick=\"news_modify('edit');\">Edit</button> "; echo"<button type='submit' onclick=\"news_modify('delete');\">Delete</button>"; echo"</form>"; So basically the idea is to fire off new_modify function and start referencing the hidden input type with name of do and set it to the supplied argument then continue submitting the form. any help is appreciated thank you. |
|
|
|
Feb 19 2008, 11:02 PM
Post
#2
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 32 Joined: 19-February 08 Member No.: 58,129 |
so do you want the button to disable after submission? I'm not sure if i understand the question very well
|
|
|
|
Feb 19 2008, 11:12 PM
Post
#3
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
No I'm trying to control the
<input type='hidden' name='do' value='' /> to be set as either 'edit' or 'delete' depending on what ever button was pushed then submit. |
|
|
|
Feb 19 2008, 11:28 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 281 Joined: 5-October 07 From: Random Places Member No.: 51,171 ![]() |
I believe there is a way to retrieve objects by name. You could always use that. I don't know exactly how to though.
|
|
|
|
Feb 20 2008, 05:16 AM
Post
#5
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 30 Joined: 23-November 06 Member No.: 33,877 |
If you don't want to use id, you need to know the sequence number of the form in the display.
First, you need to access the form object. With id, you can access the form object by using: document.getElementById('$rs['id']) otherwise, you can access it using: document.forms[<form number>] CODE [/codebox] Because I don't know the sequence number of your form, I will use form id instead. I will use id 'form1' for simplicity. [codebox] <script type="text/javascript"> function news_modify(type) { if(type=='edit'){ document.getElementById('form1').do.value='edit' } else if(type=='delete'){ document.getElementById('form1').do.value='delete2' } document.getElementById('form1').submit(); } <form method='post' action='manage.php?manage=news&id='form1'> <input type='hidden' name='do' value='' /> <button type='submit' onclick="news_modify('edit');">Edit</button> <button type='submit' onclick="news_modify('delete');">Delete</button> </form> </script> Hope it helps This post has been edited by apacheNewbie: Feb 20 2008, 05:19 AM |
|
|
|
Feb 20 2008, 07:23 AM
Post
#6
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
I found the solution to this problem
CODE function news_modify(e, action) { var targ; if (!e) { var e=window.event; } if (e.target) { targ=e.target; } else if (e.srcElement) { targ=e.srcElement; } if (targ.nodeType==3) // defeat Safari bug { targ = targ.parentNode; } var tname; tname=targ.tagName; var targ_do = targ; while(targ_do.name != 'do') { targ_do = targ_do.previousSibling; } targ_do.value = action; //var form = targ.parentNode; //form.action = form.action + '&do='+action; } and when you call it on <button onclick="news_modify(event, action);" . You must supply the object (I think thats what it is called) event or else it wont work. That function will get the object button and travel up looking for other siblings belonging to the same parent "Form" and get the hidden input with name of 'do'. Although this works a better solution to what I wanted to do didn't required this. I was just not using the form correctly. I could have the same effect and control with CODE echo"<form method='get' action='manage.php'>"; echo"<input type='hidden' name='manage' value='news' />"; echo"<input type='hidden' name='id' value='{$rs['id']}' />"; //echo"<input type='hidden' name='do' value='' />"; echo"<button name='do' value='edit' type='submit' >Edit</button> "; echo"<button name='do' value='delete' type='submit' >Delete</button>"; echo"</form>"; Its simple yeah I cant believe I didn't know how you could use buttons like that. So in this scenario what ever button is pressed you are able to to submit 'do' with the correct value and then process your page with control. I hope this helps anyone with a similar problem. sone. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 27th July 2008 - 01:15 AM |