Populating a Modal contact form on click with javascript - forms

I have a modal form which loads upon clicking an anchor tag with a specific class.
What I am trying to achieve is to apply a value to a certain text field within the mdoal form when the anchor tag is clicked.
I have this function working to a point with the following, when the anchor tag is clicked the input field with the id="contact-catalogue" is populated with the value set within anchor tag:
<input type="text" id="contact-catalogue" />
<a class="button-left contact" href="#" onclick="document.getElementById('contact-catalogue').value='link2';">Request</a></div>
My problem is that the modal form loads when the anchor tag is clicked and the value set within the anchor tag does not populate the required text field.
My guess is that because the form loads after anchor tag is clicked there is no ID being picked up and that is why the value is not being passed.
Any help would be greatly appreciated....

So I have come up with a solution on how to populate the input field within the Modal form upon the onclick event.
Basically I set a delay on the onclick event which gives the modal window enough time to load. This allows the onclick event to find the ID of the inputfield within the form and populate it with the value that I require:
<a class="button-left contact" onclick="setTimeout(function() {document.getElementById('contact-catalogue').value='AS101'}, 1000);" href="#">Kit Insert Request</a></div>
I hope this helps anyone in a simialr situation in the future.

Related

Show search history in ionic

So I want to create a modal-like behavior for the search.
When the ion-searchbar is focused, a modal would slide from the bottom showing search history, which would hold the suggestion once the user starts typing. The problem with ionic nodals is the backdrop, I couldn't keep the ion-searchbar active to input search words.
This component is called Popover, you can create them pretty much like you do with a modal but using an PopoverController instead. The PopoverController.create() method has an event parameter that will tell which element will be the anchor for the popover, set that to your search bar and it should be magically aligned.
By default a backdrop is shown when the popover is created but it can be deactivated via showBackdrop property upon creation.
Take a look at the Ionic's Popover API Docs for further information
I ended up by using segments, as below:
<div *ngIf="segment == 'prodSection'">
...
</div>
<div *ngIf="segment == 'searchSection'">
...
</div>
I styled the two divs in a way to be on top of each other and added events to the searchbar like:
<ion-searchbar (ionFocus)="openSearch()" (ionCancel)="retProd()"></ion-searchbar>
And toggeled between the segments with setting the segment variable's value with each event.

How can I keep the selection of a radio button on a form if a page reloads

Good day,
Part of a form I created consists of two groups of radio buttons that display specific text depending on which button is selected.
If a user clicks the submit button, but hasn't incorectly inputed something wrong (or has missed a field), the page reloads and displays an error at the top. Unfortunately, the radio button are resetted to no selection, so the user has to choose the options again in order to display the relevant text that needs to be amended.
How can I make it so the radio buttons do not reset once the page reloads (i.e. there selections will be saved)?
Note: I cannot stop the page from reloading after a user clicks submit; it's just the way the CMS is set up.
I've tried some scripts and searched Google, but I cannot seem to get anything to work due to the restrictions of the ancient CMS I'm working with.
<p id="submit">Please select one of the following:<strong class="required" style="color:red">(required)</strong></p><div>
// Here is one of the radio button groups that need to be saved. You'll notice that they are calling a script to display specific text when selected
<input type="radio" name="type" id="selection1" onclick="myOwnBehalf()" required> I am submitting this question on my on own behalf.<br/>
<input type="radio" name="type" id="selection2" onclick="onBehalfSomeone()" required> I am making this question on behalf of someone else.<br/>
<input type="radio" name="type" id="selection3" onclick="anon()" required> I would like to be anonymous.<br/>
....
The radio button selections are reset to blank once the page reloads because the users filled it out incorrectly.
Each time you navigate to a new page (or back to the same page) all of the JavaScript state is lost.
That means you need to pass the old state to the new page one way or another. Here are some ways of doing this:
These require using a scripting language like PHP for your pages:
PHP session (if you're using the PHP scripting language)
Navigate using form POST instead of a simple link
These could be done with just JavaScript
CGI variables in the URL you navigate to, for example mypage.php?choice1=3&choice2=5
Set a cookie then read it
HTML5 LocalStorage
(CGI variables: How to get the value from the GET parameters? )

How to make sap.m.Text focusable?

Simple problem in fact.
I am displaying some Text using sap.m or sap.ui.commons elements.
I cannot access any of them using the arrows (cursors).
I succeed navigating to input fields, rows in table but not Text.
I looked for any help on the net but without success.
if i grasp the question right, then the desire is to have a click event for sap.m.Text. I.e. a click on a sap.m.Text control triggers a event which leads to a method in the corresponding controller of the view in which the control sits.
sap.m.Text does not feature any click event by standard. instead please use sap.m.Link. sap.m.Link has the press event which is a click event. e.g. in a xml view:
...
<Link
text="clickMe"
press="onClickMethod">
</Link>
...

jquery UI tabs switches to first tab if a submit is made

I have a site where I use jquery ui tabs and in the first tab I display general information and on the second tab I have a form that I would like it to send back some information to the server via xml (ajax-style); update the database and subsequently return information for that same tab to update itself. It appears, however, that whenever a form is submited within a jquery ui tab that there is no way to prevent the "refresh"-style effect and handle the form in a way that the submit doesn't effectively take place thus keeping the active tab still the same. I've tried several approaches such as onclick="return 0;" onsubmit="return 0;" and some snippets to cancel events but I don't seem to be very successful. Has anyone gone through the same problem before?
Thanks!
If you want to do an ajax request, you can omit the <form></form> tag, so when the submit button is clicked, the form is not submitted (no refresh/postback) because the form and its action value doesn't exist. Then just handle the submit button click event and do your ajax stuff from there.
I think you can also return false when the submit button is clicked. ie: <input type="submit" value="Go!" onclick="dostuff(); return false;">

How to add a combobox and a button to the infoWindow on Google map?

Currently, I'm developing an application, in which I have to show an infoWindow on click event on map itself.
My question is I want to show a button as well as a combobox on this infoWindow.
How can I do this?
You need to add a custom UIView to your MKMapView and supress the default MKAnnotation callout view. Your custom UIView can include the controls you want in the callout.
You might find the following useful:
customize callout bubble for annotationview?
A development blog with some posts on customizing MKMapView.
I don't think either of these posts describe a definitive, clean solution to your problem (scrolling problem with the subview position). I suggest you re-think your UI and consider pushing an entirely new view from the standard callout right disclosure button. I feel like customizing the callout (infoWindow equivalent) doesn't translate well to the iPhone platform.
Edit:
Ok. So all you want to know is how to show a check box in an infoWindow using the regular Google Maps Javascript API?
That is a much easier question. If you have a look at the GMarker openInfoWindow, you will find that the first paramter to this method is a string. This string needs to be populated with the HTML that you would like in your infoWindow. So for your checkbox and button you need an input element of type checkbox and button:
<input type="checkbox" name="vehicle" value="Airplane" />
<input type="button" value="Blah" />
Why don't you use the content attribute of InfoWindow itself?
myWindow = new google.maps.InfoWindow({
content:'<input type="checkbox" name="vehicle" value="Airplane" /><input type="button" value="Blah" />',
});
myWindow.open(map, marker);