Forum Moderators: coopster

Message Too Old, No Replies

How to pull out value from the selected flag?

         

toplisek

12:34 pm on Sep 29, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have code like:
<div class="selected-flag" tabindex="0" title="Germany (Deutschland): +49"><div class="iti-flag de"></div><div class="iti-arrow"></div></div>

It should pull out value +49 but how to do it as there is not name like
<input id="" type="phone" name="myintext1" ...

Should I add some Id or name? Need help what is the best solution.

whitespace

12:57 pm on Sep 29, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Where is this HTML code? How does PHP fit into this? Is this part of a form that is submitted to the server? Or is this HTML constructed on the server and you need to extract this information (from the HTML "string") before sending it to the client?

Or, should you be looking at JavaScript (ie. client-side), not PHP?

whitespace

8:17 pm on Sep 29, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Just to add... if this is part of a FORM (as your example seems to suggest?) then no part of this DIV element is going to be sent back to the server anyway, regardless of whether you have ID or NAME attributes. Only information stored in INPUT elements is actually sent back when the form is submitted.

toplisek

8:23 pm on Sep 30, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry for this confusion.

Please find that this is injected inside FORM element. I get value for my phone element but international extension is not received.

name="myintext1" will be received as this is phone number, but an issue is with the extension. Is there possibility to add name="myextension1" ?

Just example what I mean:
<div class="selected-flag" tabindex="0" title="Germany (Deutschland): +49" name="myextension1">

I do not imagine to solve this via PHP as it is pure HTML issue or Javascript.

Maybe title can be captured using PHP...and than make it shorter:Germany (Deutschland): +49

whitespace

10:11 pm on Sep 30, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Is there possibility to add name="myextension1" ?


As mentioned, you can't simply add a NAME attribute to a DIV element and expect this to get sent back with the form submission. (How/when would you add this NAME attribute anyway?)

You could generate an INPUT element, using JavaScript (on page load?), that contains the value of the TITLE attribute (of that DIV) as the input's VALUE. This would then be submitted with the form data. But from the HTML snippet you've provided, this looks tricky to target (ie. there's no ID attribute) - this would possibly be dependent on the page structure and relationship between the elements.

HOWEVER, there's something not right here / missing information... how is this form generated? Isn't the "extension" known at the time the form is generated? Where does this information come from in the first place? Or is this DIV somehow dependent on a user action in the form and the extension can vary?!

toplisek

1:22 pm on Oct 1, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<!DOCTYPE HTML>

<html>

<head>
<title>Pull out extensions</title>
</head>

<body>
<form id="" class="myclass1" action="" method="post">

<label class="myclass1">Phone number:</label>

<div class="selected-flag" tabindex="0" title="Germany (Deutschland): +49" name="myextension1"></div>

<input id="myid1" name="myname1" class="myclass1" type="phone">
</form>
</body>

</html>

Sample at URL:
1. [github.com ]
2. [codepen.io ]
Selected flag:
3. [github.com ]

This is just example how it is managed form. An issue is with the extension. DIV element shows +49 but this is not input.