forms - show and hide div on an onclick event bypassing a onblur event in javascript -


I have a textfield that uses a blurb event to format the numbers in the currency. I want to run my onclick function which first hides on a single device before the values ​​of the stigma. Every time I click in the field, then the problem is not lost and when I run my values ​​in the formula after the stigma, then do not count. I added an alert function to the blur function and the warning message was looping. I hiding a show every time in the Textfield inventing Div function.

  & lt; Input name = "txtA" type = "text" id = "txtA" value = "& lt; php if (isset ($ _ POST ['calculate'])) {echo 'r' .number_format ($ _ [session ' [Salesprice '], 2);} and {$ e_SO] [' salesprice ']; gt; size = "50" onblur = "this.value =' R '+ format number (this .view, 0, 0, True); "Onclick =" return document.getElementById ('linkContainer2'). InnerHTML = myFunction (); "/ & gt; & lt; div id =" linkContainer2 "& gt; My content & lt; / div & gt; & lt; script & gt; function myFunction (DivTest = document.getElementById ('linkContainer2'); if (divTest.style.display === "none") {divTest.style.display = 'block';} and {divTest.style.display = " None ";}}   

following your code It's hard to do, because you're combining PHP, HTML, and JavaScript into a big pile. Instead, I've separated each language for you:

  & lt; ? Php $ value = $ _SESSION ['sold' Rectus']; if (isset ($ _ POST ['calculation']) $ value = number_format ($ _ session ['salesprice'], 2);? & Gt; & lt; input id = "txtA" name = " TxtA "type =" text "value =" & lt ;? = $ value ???? & gt; size = "50" /> 
3? H% 3: 0; Returns s + (j? Iusubstr (0, j) + t: "") + i.substr (j) .replace (/ (\ d {3}) (? = \ D) / g, "$ 1 "+ T) + (C + D + Math. Abbas (N - I). Toofics (C). Slice (2):" "); }; Element.prototype.addEvent = function (eventName, callFunction) {if (this.addEventListener) this.addEventListener (eventName.substring (2), call function, incorrect); Else if (this.attachEvent) this.attachEvent (eventName, call function); }; Get function (AL) {if (L) {ifof l === 'string' ||! Noen (L)) {if (el == 'document.body') Return Document. Return document. GetElementById (L); } Else {if (el.id) {if (document.getElementById (el.id)) return document.getElementById (el.id); And if returned (typo L == '') L; } And return back; } } return false; } ('TxtA'). AddEvent ('onfocus', function () (get (' linkContainer2 '). Style.display =' none ';}); add (' txtA ') addEvent (' onblur ', function () {this.value =' $ '+ This.value.formatCurrency (2,'. ',', ');}); & Lt; / script>

You can do the following here: < / P>


As a bonus, I have some hints that can be useful:

  1. You can enter innerHTML Code> linkContainer2 to <=> myfunction . In theory it is alright, but in your case myfunction does not always give anything, in other words, You anything to it Were not set.

  2. Inside myfunction , I was re-setting your innerHTML That we can do whatever you want without myFunction .

  3. instead of onclick , I onFocus .

  4. I've split your PHP, HTML and JavaScript into 3 separate pieces. I know that it may look like a waste of time, but investing that little extra time makes your life easier for a long time. Such debugging problems take more than half the time. I highly recommend writing your projects in the future.

  5. I did not know why you used to toggle the display of linkContainer2 , so I just used its display always < Code> = none . If you are required, you can add your statement back then.

  6. I've included some extra JavaScript functionality that you can find useful. My gets changes the function to document.getElementById , which makes it easier to read your code, I have the addEvent , and formatCurrency < / Code>, which makes your life even easier.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -