Jump to content

func to readonly textbox on radio click


UnknownPlayer

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>

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.