Jump to content

Input Display


ShadowMage
 Share

Recommended Posts

I don't know if this can be done but I thought I'd ask. I did a little bit of research but I couldn't find anything as I wasn't quite sure what to search for.Anyway, here is what I'd like to do.I have a text box where I display some values. These values can be changed by the user but by default the value is pulled from a database where the default value is stored. What I'd like to know is if it is possible for a text box to display this default value but have the text boxes value attribute empty.I realize this is probably a long stretch but any advice/help is very much appreciated.Thank you,jkloth

Link to comment
Share on other sites

No. The value property of a text input or a textarea is the text that is displayed.If its the display you are interested in, you can play tricks that sort of work, like setting the color of the text to the same color as the background of the input.If it is the actual information that interests you, then you can store alternate text in a JavaScript variable, or even give the text element a new property that contains the text but doesn't display it. Again, that's JavaScript, not something that happens in the HTML tag.Maybe we could come up with better solutions to your problem if you explained what you're really trying to accomplish.

Link to comment
Share on other sites

I'm not sure how I can explain to make it clear but I'll try.I have a checkbox and a couple select boxes. The selects list some specific types of materials. This list is pulled from the database where the descriptions and base prices for the materials are also kept. The checkbox is a manual override for the prices. If it's checked text boxes appear to allow the user to edit the prices. What I would like to do is display the base prices in the text boxes but keep the value of the text boxes empty. The reason I want the value to stay empty is this:I do some calculations that check if the value of the text boxes is empty and if so I get the base prices from the database. If they are not empty I use the values in those text boxes for the calculations. Since the prices change relatively frequently it wouldn't make sense to compare the value to the base price so I compare it to an empty string instead.Does this make sense?

Link to comment
Share on other sites

It sounds like you're using javascript to make things appear or disappear. So we can do this all with javascript.1. When a text input has a value hard-coded in the element tag, its defaultValue property is set to the same value. (This is a DOM property accessibly with javaScript.) The user can change the value property just by editing the text. But the default value remains unchanged. So you can always compare those values, or simply use the default value to restore the displayed value to its original value. Read more.2. You can create your own properties for a page element using JavaScript. They can have any name you want. So if you have a text input, and its id is "Ford," you could do this:document.getElementById("Ford").basePrice="50.00";and then access that property in the usual way.3. Store information in JavaScript objects that are associated with your page elements in some way (probably the id attribute). That might look like this for just ONE product:product = "shoe";num++;id = product + num;inventory[id] = {}inventory[id]["baseprice"] = "50.00";inventory[id]["color"] = "Red";//etc.So now you can get the id of your text input and plug it into your inventory object to get the base price. (I tossed in the color attribute just to suggest possibilities.)---If none of that can be adapted to your system, maybe you could explain more. Like: what is the role of JavaScript in this process, what exactly happens when the text boxes "appear," how do their values get initialized, is this whole document being generated through PHP or something, etc.

Link to comment
Share on other sites

I'm thinking I can probably use the defaultValue property to do what I want I'm just not quite sure how.I guess the JavaScript isn't really the issue. I also have a checkbox (as I believe I mentioned earlier) which is what toggles the display of the text boxes. In javascript the calculations done on with the prices only used the text boxes value if the checkbox is checked.Where I'm really concerned is reposting to PHP. How can I POST the defaultValue if either the box is unchecked or the text box is displaying the default base price? The reason I am POSTing is because this information is also saved to a different table.Hopefully this is clear enought?Thank you for the great suggestions.

Link to comment
Share on other sites

Whatever is displayed will be posted. If you want to post both a default value and an edited value, then I suggest using an input type="hidden". You could hard-code the hidden inputs and their values, and then use javascript to adjust their value dynamically before the form gets submitted.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...