Jump to content

Recommended Posts

Let me start by saying I don't know JS. I only know PHP/HTML.

 

That being said, I have a form with 2 input fields. I have a button. I want to press the button and have it autopopulate the two input fields.

 

example.

button: [12-84]<--- click this and input 1 now has a 12 and input 2 now has an 84 in it. They can also manually enter the date in the fields.

 

 

 

I know I can do

<script>

function transferField(someval){

document.form.code.value = someval;

}

</script>

<input button id=code onclick="transferField(this.value)"....>

blah blah...

 

but that only does a single field. I want the one button click to do to values to two seperate input fields.

 

Thanks :)

 

Link to comment
https://forums.phpfreaks.com/topic/264390-input-field/
Share on other sites

How do I "split" the value?

 

<input value="12-99"...>

 

I want the substring 12 in the first input field and 99 in the second input field.

 

You can use split():

 

var parts = someval.split('-');
// parts[0] now contains "12"
// parts[1] now contains "99"

 

is document.formName.inputName1.substring(someval(0,1)) (not sure of the JS syntax) valid?

 

Not quite. You want to select a sub-string of someval; currently you're trying to select it from the input's DOM object. With the parts array though you don't need to use substring:

 

document.formName.inputName1.value = parts[0];
document.formName.inputName2.value = parts[1];

Link to comment
https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355138
Share on other sites

How do I "split" the value?

 

<input value="12-99"...>

 

I want the substring 12 in the first input field and 99 in the second input field.

 

You can use split():

 

var parts = someval.split('-');
// parts[0] now contains "12"
// parts[1] now contains "99"

 

is document.formName.inputName1.substring(someval(0,1)) (not sure of the JS syntax) valid?

 

Not quite. You want to select a sub-string of someval; currently you're trying to select it from the input's DOM object. With the parts array though you don't need to use substring:

 

document.formName.inputName1.value = parts[0];
document.formName.inputName2.value = parts[1];

 

Thanks for helping. One final little question. If parts[0] corresponds to a pulldown rather than a text input, would it still work?

 

Apple <----value=1

Banana <--Value = 2

Frog<-------Value = 3

 

??

 

Link to comment
https://forums.phpfreaks.com/topic/264390-input-field/#findComment-1355235
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.