Jump to content

[SOLVED] Need Function to Work With Multiple Forms


limitphp

Recommended Posts

Is it possible to change this part in a function used by multiple forms:

function myfunc(num){

  document.frmPlaylist.newName.value;

}

 

into this:

function myfunc(num){

  document.frmPlaylist+num.newName.value;

}

 

in other words, I have a page that may have a bunch of forms on it....

each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc....

 

I want to send that number to the function and make it part of the form name.  Is that possible?

 

thanks

 

 

Link to comment
Share on other sites

Is it possible to change this part in a function used by multiple forms:

function myfunc(num){

  document.frmPlaylist.newName.value;

}

 

into this:

function myfunc(num){

  document.frmPlaylist+num.newName.value;

}

 

in other words, I have a page that may have a bunch of forms on it....

each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc....

 

I want to send that number to the function and make it part of the form name.  Is that possible?

 

thanks

 

 

 

Use something along the lines of:

function myFunc(num)
{
   document.forms["frmPlaylist" + num].elements["newName"].value = "blah";
}

Link to comment
Share on other sites

Is it possible to change this part in a function used by multiple forms:

function myfunc(num){

  document.frmPlaylist.newName.value;

}

 

into this:

function myfunc(num){

  document.frmPlaylist+num.newName.value;

}

 

in other words, I have a page that may have a bunch of forms on it....

each form would be called frmPlaylist4, frmPlaylist35, frmPlaylist22, etc....

 

I want to send that number to the function and make it part of the form name.  Is that possible?

 

thanks

 

 

 

Use something along the lines of:

function myFunc(num)
{
   document.forms["frmPlaylist" + num].elements["newName"].value = "blah";
}

 

How would I do that with checkboxes, if I had multiple ones with the same name?

right now i use:

document.frmPlaylist.playlist[a].checked

 

would I convert that into this:

document.forms["frmPlaylist" + num].elements["playlist"][a].checked

?

 

 

 

Link to comment
Share on other sites

Why not just pass "this" into the function?

 

 

For example:

 

<form onsubmit="SomeFunction(this);">

 

 

Then the parameter would be the same thing as what you would get with document.formname.

 

thanks for the tip corbin, I thought about that...but I can't....because I call the function when they click the submit button, not the checkboxes and textbox.....

 

its complicated.....its for an ajax request.....

 

anyway, Nightslyr, it worked!!!!!!

 

my goodness, you are awesome!

 

 

Link to comment
Share on other sites

What does a submit button do?  It submits a form >.<.

 

 

If you do onsubmit="blah(); return false;"

 

 

The form will not submit.

 

Actually thats not true....I tried that.

I moved my ajax call to the <form tag instead of the button and when I tried to put the ajax function in front of the return false, it submitted the darn thing.....

 

anyway, I really appreciate you responding corbin.  You're always willing to help m out and I really appreciate that.  Even when Maq and premiso get tired of my butt.

 

ultimately, I like using this:

document.forms["frmPlaylist" + num].elements["newName"].value = "blah";

 

because it gives you even more control....

Link to comment
Share on other sites

Example of non-submitting form:

 

<script language="javascript">
function blah(f) {
return false;
}
</script>

<form action="blah.html" method="GET" onsubmit="return blah(this);">
<input type="hidden" name="hidden" value="omg a value!" />
<input type="submit" />
</form>

 

 

But, what ever works ;p.

Link to comment
Share on other sites

Example of non-submitting form:

 

<script language="javascript">
function blah(f) {
return false;
}
</script>

<form action="blah.html" method="GET" onsubmit="return blah(this);">
<input type="hidden" name="hidden" value="omg a value!" />
<input type="submit" />
</form>

 

 

But, what ever works ;p.

 

Oh yeah...I could have just put it all in one function.....

yeah, I guess that would have worked too...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.