Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP text box help

Options
  • 25-04-2006 4:45pm
    #1
    Registered Users Posts: 4,037 ✭✭✭


    I have an ASP page that has a text box in it and the contents of it are entered into a table once you click OK elsewhere on the page. The trouble is that the text box has to be disabled (made non-editable) before you click OK.
    It is an Oracle table and when data from a text box which has been disabled is entered it does not go in to the table.
    There are other fields on the page and the contents of those go into the table fine but the field I want to be filled with the data from the text field is blank when I look at the table.

    This is the line of code that inserts into the field;

    BugDesc = server.HTMLEncode(rsBug("bug_desc"))

    The variable 'sBugDesc' is coming from the text field that I am trying to insert. "bug_desc" is the field in the table I am trying to insert it into.
    The problem is with the 'server.HTMLEncode'. Presumably it can't do this to a field that has been rendered uneditable. The funny thing is that when I leave the text box empty it enters all the other stuff in the page OK.. It's obviously a problem with the fact the data has been made uneditable.
    Any help would be greatly appreciated, thanks.


Comments

  • Closed Accounts Posts: 1,200 ✭✭✭louie


    if the field is disabled try to get the data into a hidden field with the same name as the text field


  • Registered Users Posts: 4,037 ✭✭✭lukin


    Not a bad idea.I'll try it


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Hi,

    Are you using the "disabled" attribute? As far as I know, this actually disables the form field, making it unreadable to the webserver as well as the user. Use the "readonly" attribute instead.

    Eoin


  • Registered Users Posts: 4,037 ✭✭✭lukin


    Doesn't work 'cause the text box doesn't become disabled when I do that.
    Thanks anyway.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    lukin wrote:
    Doesn't work 'cause the text box doesn't become disabled when I do that.
    Thanks anyway.

    Are you using Javascript to do this before the submit? If you post some code, it would be a little clearer.


  • Advertisement
  • Registered Users Posts: 4,037 ✭✭✭lukin


    eoin_s wrote:
    Hi,

    Are you using the "disabled" attribute? As far as I know, this actually disables the form field, making it unreadable to the webserver as well as the user. Use the "readonly" attribute instead.

    Eoin

    That attribute works if I put it directly into the textarea tag (see below)

    <textarea " readonly type="text" name="dfBugDesc" class="fulltextarea"></textarea>

    But I want it to be "readonly" depending on whether a checkbox elsewhere on the page is checked or not. I don't know if I can change that attribute from true to false from outside the textarea tags.
    I'll work on it further anyway.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    lukin wrote:
    That attribute works if I put it directly into the textarea tag (see below)

    <textarea " readonly type="text" name="dfBugDesc" class="fulltextarea"></textarea>

    But I want it to be "readonly" depending on whether a checkbox elsewhere on the page is checked or not. I don't know if I can change that attribute from true to false from outside the textarea tags.
    I'll work on it further anyway.

    I see the problem now, seems to be awkward to change the readonly tag using JavaScript - like someone said earlier, probably easiest to use a hidden text field, and set the value of the hidden field to the value of the textarea whenever the checkbox is clicked. The hidden text field will be available to the ASP, even if the textarea isn't.

    example below:
    <html>
    	<head>
    		<title>test form</title>
    	</head>
    	<script type="text/JavaScript">
    	function doTextArea()
    	{
    		document.getElementById("txtBugDescShow").value = document.getElementById("dfBugDesc").value;
    		if (document.getElementById("chkOn").checked)
    		{
    
    			document.getElementById("dfBugDesc").disabled = true;
    		}
    		else
    		{
    			document.getElementById("dfBugDesc").disabled = false;
    		}
    	}
    	</script>
    	<body>
    		<form name="myFrm" action="testform.asp" method="post">
    			<input type="checkbox" id="chkOn" value="on" onclick="doTextArea()">Disable?<br>
    			<textarea id="dfBugDesc" type="text" name="dfBugDesc"></textarea><br>
    			<input type="text" name="txtBugDescShow" id="txtBugDescShow" value=""><br>
    			<input type="submit" name="cmdSubmit"><br>
    		</form>
    	</body>
    </html>
    


  • Registered Users Posts: 4,037 ✭✭✭lukin


    Thanks eoin_s, that inserts the text into the field now. Only trouble now is it only goes in if the check box is checked. I think that checkbox has to be checked before everything goes into the table though so that shouldn't be a problem.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    lukin wrote:
    Thanks eoin_s, that inserts the text into the field now. Only trouble now is it only goes in if the check box is checked. I think that checkbox has to be checked before everything goes into the table though so that shouldn't be a problem.

    oops, then what you can do is add a function that is called when the form is submitted that does the same thing as the checkbox:
    <html>
    	<head>
    		<title>test form</title>
    	</head>
    	<script type="text/JavaScript">
    	function doTextArea()
    	{
    		document.getElementById("txtBugDescShow").value = document.getElementById("dfBugDesc").value;
    		if (document.getElementById("chkOn").checked)
    		{
    
    			document.getElementById("dfBugDesc").disabled = true;
    		}
    		else
    		{
    			document.getElementById("dfBugDesc").disabled = false;
    		}
    	}
    	function submitForm()
    	{
    		document.getElementById("txtBugDescShow").value = document.getElementById("dfBugDesc").value;
    	}
    	</script>
    	<body>
    		<form name="myFrm" action="testform.asp" method="post" onsubmit="submitForm()">
    			<input type="checkbox" id="chkOn" value="on" onclick="doTextArea()">Disable?<br>
    			<textarea id="dfBugDesc" type="text" name="dfBugDesc"></textarea><br>
    			<input type="text" name="txtBugDescShow" id="txtBugDescShow" value=""><br>
    			<input type="submit" name="cmdSubmit"><br>
    		</form>
    	</body>
    </html>
    


  • Registered Users Posts: 4,037 ✭✭✭lukin


    Thanks again man but I did a bit of testing and the form cannot be submitted without the checkbox being ticked. Sorry you wrote that function for nothing!


  • Advertisement
  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    lukin wrote:
    Thanks again man but I did a bit of testing and the form cannot be submitted without the checkbox being ticked. Sorry you wrote that function for nothing!

    No worries, was only a few mins work anyway :)


  • Registered Users Posts: 4,037 ✭✭✭lukin


    eoin_s wrote:
    No worries, was only a few mins work anyway :)

    Yeah, for you!


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    lol man. wasn't the hidden field enough?
    What exactly are you trying to do?


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    Nice one eoin_s, have a use for that in a few weeks and that saves cooking it up, will stick in in me js lib.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    democrates wrote:
    Nice one eoin_s, have a use for that in a few weeks and that saves cooking it up, will stick in in me js lib.

    So it wasn't all in vain then :)


  • Registered Users Posts: 4,037 ✭✭✭lukin


    louie wrote:
    lol man. wasn't the hidden field enough?
    What exactly are you trying to do?

    There a lot of textboxes, drop-down combo boxes and checkboxes on the page. When the user enters text into a particular text box it requires ticking a check box. Once you check this box it disables the textarea.
    Then you click on "OK" and everyting on the page (and believe me it is a lot of stuff!) goes into the table.
    The problem I had was text from a textbox that has been made disabled was not getting entered into the table.
    Your idea of adding a hidden field was right but giving it the same name was not working.
    I had to add the "value" attribute to the hidden table, set it to an empty string and then assign it the contents of the text box I wanted entered into the table.
    I also had to make sure I did this BEFORE the text box became disabled.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    you could have the hidden field as a back-up for the text in the textarea. if the textarea had no value (disabled) then you could have the database updating the field from the hidden value or better skip it and leave as it was, updating the other fields.

    If the textarea has been changed, meaning it wasn't disabled then you could have the update sql adding that field and value as well.


  • Registered Users Posts: 4,037 ✭✭✭lukin


    Well the thing is the text box could be disabled and have text in it.
    The idea is you enter text to the text box, click the check box and then the text box is disabled so you can't enter any more text.
    The text in the text box has to go into the table though even if it is greyed out.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    sounds complicated, but i don't understand why you have to disable it?


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Lukin,

    Just make sure that the hidden field has it's value set to the value of the textarea upon both the clicking of the checkbox, and submission of the form. If you want to be sure, you can also do it on the onblur event of the textarea. Then in your ASP, use the value of the hidden field - not the textarea. The hidden field and textarea should not have the same name / ID.

    I am pretty sure that disabling a form field disables both user input, and also effectively removes it from the form altogether, so it will not appear in the Request.Form collection.

    Eoin


  • Advertisement
  • Registered Users Posts: 4,037 ✭✭✭lukin


    Ask my boss!I was just told this field (the text box) cannot be modified once this box (the check box) is checked.
    Silly business rules.


Advertisement