Jump to content

input field


AV1611

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.