<html>
<head />
<body>
...
<select name="originator">
<option selected value="0">Company A</value>
<option value="1">Company B</value>
<option value="2">Company C</value>
</select>
...
<select name="underwriter">
<option value="-1">Please select</value>
<option value="9005">Company A</value>
<option value="9006">Company B</value>
</select>
...
</body>
</html>
Then it's time to use the XML functions provided by the good people of Mercury (now HP), first extract the options inside the select element by using web_reg_save_param function:
web_reg_save_param("pOriginatorIDText",
"LB/IC=name=\"originator\"",
"RB/IC=</select>",
"Ord=1",
"Search=body",
LAST);
web_reg_save_param("pUnderwriterIDText",
"LB/IC=name=\"underwriter\"",
"RB/IC=</select>",
"Ord=1",
"Search=body",
LAST);
Follow by the functions to extract the related values:
iNumOfValues = lr_xml_get_values("XML=<select {pOriginatorIDText}</select>",
"ValueParam=pCollectedOriginatorName",
"Query=/select/option",
"SelectAll=yes",
LAST);
iNumOfValues = lr_xml_get_values("XML=<select {pOriginatorIDText}</select>",
"ValueParam=pCollectedOriginatorID",
"Query=/select/option/@value",
"SelectAll=yes",
LAST);
for (i = 0; i < iNumOfValues; i++) {
sprintf(buf, "{pCollectedOriginatorName_%d}", i+1);
sprintf(buf, rtrim(lr_eval_string(buf)) );
sprintf(sParamName, "pCollectedOriginatorName_%d", i+1);
lr_save_string(buf, sParamName);
if (strcmp(buf, lr_eval_string("{pOriginatorName}")) == 0) {
lr_output_message("Originator name found");
sprintf (buf, "{pCollectedOriginatorID_%d}", i+1);
lr_save_string(lr_eval_string(buf), "pOriginatorID");
}
sprintf (buf, "Retrieved value %d : {pCollectedOriginatorName_%d}", i+1, i+1);
lr_output_message(lr_eval_string(buf));
}
//#####################################
iNumOfValues = lr_xml_get_values("XML=<select {pUnderwriterIDText}</select>",
"ValueParam=pCollectedUnderwriterName",
"Query=/select/option",
"SelectAll=yes",
LAST);
iNumOfValues = lr_xml_get_values("XML=<select {pUnderwriterIDText}</select>",
"ValueParam=pCollectedUnderwriterID",
"Query=/select/option/@value",
"SelectAll=yes",
LAST);
for (i = 0; i < iNumOfValues; i++) {
sprintf(buf, "{pCollectedUnderwriterName_%d}", i+1);
sprintf(buf, rtrim(lr_eval_string(buf)) );
sprintf(sParamName, "pCollectedUnderwriterName_%d", i+1);
lr_save_string(buf, sParamName);
if (strcmp(buf, lr_eval_string("{pUnderwriterName}")) == 0) {
lr_output_message("Underwriter name found");
sprintf (buf, "{pCollectedUnderwriterID_%d}", i+1);
lr_save_string(lr_eval_string(buf), "pUnderwriterID");
}
sprintf (buf, "Retrieved value %d : {pCollectedUnderwriterName_%d}", i+1, i+1);
lr_output_message(lr_eval_string(buf));
}
Yes, it looks complicated, but:
pOriginatorID = 0
pUnderwriterID = 9005
No comments:
Post a Comment