Jump to content

Recommended Posts

Need help with function to make "file" textbox read only, onclicl event, when radio("pic")  is value "1" or "3".

Form:

<form id="contacts-form" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000" /><input type="hidden" name="aid" value="'.$aid.'" />
<div class="field"><label>Naziv:</label> <input type="text" name="name" value="'.$name.'" /></div>
<div class="field"><label>Sastojci:</label> <input type="text" name="info" value="'.$info.'" /></div>
<div class="field"><label>Cena:</label> <input type="text" name="price" value="'.$price.'" onKeyUp="checkNumber(this);" />RSD.</div>
<div class="field"><label>Promeni sliku:</label> <input name="file" type="file" /></div>
<div class="field"><label>Ostavi postojecu sliku</label> <input type="radio" name="pic" value="1" checked ></div>
<div class="field"><label>Postavi novu sliku</label> <input type="radio" name="pic" value="2" ></div>
<div class="field"><label>Izbrisi sliku</label> <input type="radio" name="pic" value="3" ></div>

<br /><br />
<input type="submit" name="edit" value="Izmeni" />
</form>';

 

Can someone help me?

Link to comment
https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/
Share on other sites

The readonly attribute is for text input fields and password fields. Use the disabled property instead.

In the code below I loop through all the radio buttons with a tag name of 'pic'. If the value is 1 or 3

it is assigned the function that disables the file input. Otherwise the onclick event for the radio button will trigger the function that enables the file input. Here's a working: http://gonavygolf.com/test2.html

<script>
window.onload = function() {
var disableFile = function() {
	document.getElementById('uploadFile').disabled = "disabled";	
}
var enableFile = function() {
	document.getElementById('uploadFile').disabled = false;	
}

var pics = document.getElementsByName('pic');
for (var i = 0; i < pics.length; ++i) {
	if (pics[i].value == "1" || pics[i].value == "3") {
		pics[i].onclick = disableFile;
	} else {
		pics[i].onclick = enableFile;
	}
}
};
</script>

When i go to that page, default is "pic" = "1" radio, now i need to put that when load page to set disabled id "uploadFile" ?

 

That sentence makes no sense.

It make sanse.. u just need to be more helpfull..

Thank you brianlange..

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.