SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Using javascript in links
-
Oct 19, 2000, 18:41 #1
I have a small problem for you
Outline :
I have a specific application that I wish to use javascripting to submit a form. Im not too worried about compatibility less than 4 series browsers.
I wish to submit a form (is going to a database) using a link. A submit button doesnt seem to work for me as I need to also pass hidden variables with the submission to enforce the 'state' of the button pressed.
Say I have 4 links.
a, b, c, d
The page has 2 hidden inputs .
1 = False
2 = True
Pressing link 'a' I want to send an input value of 1 = False, 2 = false
Pressing link 'b' I may want to send an input value of 1 = true, 2 = false etc.
I currently achieve this with :
<a href='#' onClick="
document.FormName.HiddenAction.value='AddNew';
document.FormName.ActionLink.value='True';
this.href='javascript:submitForm()'">Add New</a>
Which submits to this function:
<script type="text/javascript" language="JavaScript">
function submitForm()
{
document.FormName.SubmitName.click();
}
<script>
Now this works fine, BUT I need a named 'Submit' button (SubmitName) for this to work. I dont want that submit button to show.
Another option seemed to be :
<a href='#' onClick="document.FormName.HiddenAction.value='AddNew';
document.FormName.ActionLink.value='True';
document.FormName.submit();">AddNew</a>
It works in IE 5.5, but not others.
What other options are possible for me?
Thanks in advance
-
Oct 20, 2000, 19:44 #2
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi JayDee & welcome to the forum
If I understand you right, all you need is the following:
function submitForm()
{
document.FormName.submit();
}
The 'submit()' method will submit whatever form FormName is along with its hidden values.
If I misunderstood your question, perhaps you should post the form as well. Or a url.
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Oct 20, 2000, 21:29 #3
Hi Vinny and thanks for the welcome
I made a similar assumption about that as well, but I get an "object doesnt support this property or method" when I attempt it.
asp is more my style, so Im not sure which part of the function isnt supported.
I guess its the onclick?
Unfortunately its a local PWS development, so I dont have a URL. I can post a compiled html source if necessary?
Again, in its current form it works perfectly, but appears to need the named submit form button. I dont
My original source was : http://developer.irt.org/script/593.htm
My main reasoning for doing it this way, was to enable the changing of 2 or more hidden form values, depending on the link that was selected.
If I can also do this with multiple submit buttons, then Ill do it that way if necessary.
Thanks for the help so far!
-
Oct 22, 2000, 18:26 #4
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi JayDee,
Regarding the form:
Does it have a name? How is it defined? Its elements, etc. The following, for example, should work:
<form name='FormName'>
<input type='hidden' name='HiddenAction' value='AddNew'
<input type='hidden' name='ActionLink' value='True'
<input......>
<input....>
<a href='#' onClick="
document.FormName.HiddenAction.value='AddNew';
document.FormName.ActionLink.value='True';
'javascript:submitForm()'">Add New</a>
</form>
Regarding your application:
Why are you using links or buttons? If I understand you right, the user can only click on one link and you want one of four sets of values sent (t/f, f/t, t/t, f/f). Why not use radio buttons? You can assign the values as follows (without any hidden fields)
<input type='radio' name='myButton' value='AddNew|True' onClick = 'javascript:submitForm()'>
<input type='radio' name='myButton' value='Update|True' onClick = 'javascript:submitForm()'>
....etc....
Vinny
Where the World Once Stood
the blades of grass
cut me still
-
Oct 22, 2000, 23:54 #5
Thanks Vinny, Ill just absorb your answer and see what changes I can make to either incorperate it or explain why I shouldnt
Thanks for your time.
Bookmarks